/**
* Copyright (c) By zengqh.
*
* This program is just for fun or demo, in the hope that it  
* will be useful, you can redistribute it and/or modify freely.
*
* Time: 2013/02/18
* File: rect.cpp
**/

#include "rect.h"

namespace HY
{

const Rect Rect::FULL(-1.0f, -1.0f, 1.0f, 1.0f);
const Rect Rect::POSITIVE(0.0f, 0.0f, 1.0f, 1.0f);
const Rect Rect::ZERO(0.0f, 0.0f, 0.0f, 0.0f);

const IntRect IntRect::ZERO(0, 0, 0, 0);

void Rect::Clip(const Rect& rect)
{
	if (rect.min_.x_ > min_.x_)
		min_.x_ = rect.min_.x_;
	if (rect.max_.x_ < max_.x_)
		max_.x_ = rect.max_.x_;
	if (rect.min_.y_ > min_.y_)
		min_.y_ = rect.min_.y_;
	if (rect.max_.y_ < max_.y_)
		max_.y_ = rect.max_.y_;

	float temp;
	if (min_.x_ > max_.x_)
	{
		temp = min_.x_;
		min_.x_ = max_.x_;
		max_.x_ = temp;
	}
	if (min_.y_ > max_.y_)
	{
		temp = min_.y_;
		min_.y_ = max_.y_;
		max_.y_ = temp;
	}
}

}